package xiaopiya.robot.system;

import xiaopiya.robot.handler.AbstractMessageHandler;

/**
 * @author Ray (ayufox@gmail.com)
 * @version 0.1
 */
public class NotifyMessageHandler extends AbstractMessageHandler
{
	private IFriendService friendService;

	public void setFriendService(IFriendService friendService)
	{
		this.friendService = friendService;
	}

	protected String handle(String from, String params) throws Exception
	{
		int status = 0;
		String[] array = params.split(" ");
		for (String param : array)
		{
			if ("-c".equals(param))
			{
				status = Friend.BOOKSTATUS_CANCEL;
			} else if ("-b".equals(param))
			{
				status = Friend.BOOKSTATUS_BOOKING;
			}
		}

		if (status == 0)
		{
			return "指定-c或-b以取消或订阅小屁牙消息服务";
		} else
		{
			this.friendService.changeBookStatus(from, status);
			if (status == Friend.BOOKSTATUS_BOOKING)
			{
				return "订阅小屁牙消息服务成功";
			}
			else
			{
				return "取消订阅小屁牙消息服务成功";
			}
		}
	}
}